package com.zp.drug.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zp.base.api.RemoteSerialNumberUtils;
import com.zp.common.core.constant.BaseConstants;
import com.zp.common.core.constant.CacheNames;
import com.zp.common.core.constant.DrugConstants;
import com.zp.common.core.constant.UserConstants;
import com.zp.common.core.utils.DateUtils;
import com.zp.common.core.utils.SnowIdUtils;
import com.zp.common.core.utils.StringUtils;
import com.zp.common.myBatis.core.page.PageQuery;
import com.zp.common.myBatis.core.page.TableDataInfo;
import com.zp.common.redis.utils.CacheUtils;
import com.zp.common.satoken.utils.LoginHelper;
import com.zp.drug.api.bo.DrugPriceBo;
import com.zp.drug.api.vo.DrugInfoVo;
import com.zp.drug.api.vo.DrugPriceVo;
import com.zp.drug.api.vo.DrugStorageDeptVo;
import com.zp.drug.entity.*;
import com.zp.drug.entity.bo.*;
import com.zp.drug.entity.vo.DrugExportMasterVo;
import com.zp.drug.entity.vo.DrugImportMasterVo;
import com.zp.drug.entity.vo.DrugStockAllLogParamVo;
import com.zp.drug.mapper.DrugExportDetailMapper;
import com.zp.drug.mapper.DrugExportMasterMapper;
import com.zp.drug.mapper.DrugImportMasterMapper;
import com.zp.drug.mapper.DrugStockMapper;
import com.zp.drug.service.*;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 药品入库主表Service业务层处理
 *
 * @author zhang peng
 * @ date 2023-06-21
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class DrugImportMasterServiceImpl implements IDrugImportMasterService {

    private final DrugImportMasterMapper baseMapper;
    private final IDrugImportDetailService drugImportDetailService;
    private final IDrugPriceService drugPriceService;
    private final IDrugStorageDeptService drugStorageDeptService;
    private final IDrugStockService drugStockService;
    private final DrugExportMasterMapper exportMasterMapper;
    private final DrugExportDetailMapper drugExportDetailMapper;
    private final DrugStockMapper drugStockMapper;
    private final DrugExportMasterMapper drugExportMasterMapper;
    private final IDrugStockAllLogService stockAllLogService;
    @DubboReference
    private RemoteSerialNumberUtils remoteSerialNumberUtils;

    // 药品基本信息
    static Map<String, DrugInfoVo> drugInfoVoMap = CacheUtils.get(CacheNames.DRUG_INFO);
    // 药品库存单位
    static Map<String, DrugStorageDept> drugStorageDeptMap = CacheUtils.get(CacheNames.DRUG_STORAGE_DEPT);
    // 获取厂商、生产商信息
    static Map<String, DrugSupplierCata> drugSupplierCataMap = CacheUtils.get(CacheNames.DRUG_SUPPLIER_CATA);

    /**
     * 查询药品入库主表
     */
    @Override
    public DrugImportMasterVo queryById(String id) {
        return baseMapper.selectVoById(id);
    }

    /**
     * 查询药品入库主表列表(分页)
     */
    @Override
    public TableDataInfo<DrugImportMasterVo> queryPageList(DrugImportMasterBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<DrugImportMaster> lqw = buildQueryWrapper(bo);
        Page<DrugImportMasterVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        result.getRecords().forEach(item -> {
            item.setStorageName(ObjectUtil.isNotNull(drugStorageDeptMap.get(item.getStorageId())) ? drugStorageDeptMap.get(item.getStorageId()).getStorageName() : "");
            item.setStorageFromName(StringUtils.isNotBlank(item.getStorageFrom()) && ObjectUtil.isNotNull(drugStorageDeptMap.get(item.getStorageFrom()))
                    ? drugStorageDeptMap.get(item.getStorageFrom()).getStorageName() : "");
            item.setSupplierName(StringUtils.isNotBlank(item.getSupplier()) && ObjectUtil.isNotNull(drugSupplierCataMap.get(item.getSupplier()))
                    ? drugSupplierCataMap.get(item.getSupplier()).getSupplierName() : "");
        });
        return TableDataInfo.build(result);
    }

    /**
     * 查询药品入库主表列表(不分页)
     */
    @Override
    public List<DrugImportMasterVo> queryList(DrugImportMasterBo bo) {
        LambdaQueryWrapper<DrugImportMaster> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<DrugImportMaster> buildQueryWrapper(DrugImportMasterBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<DrugImportMaster> lqw = Wrappers.lambdaQuery();
        lqw.eq(StringUtils.isNotBlank(bo.getDocumentNo()), DrugImportMaster::getDocumentNo, bo.getDocumentNo());
        lqw.eq(StringUtils.isNotBlank(bo.getStorageId()), DrugImportMaster::getStorageId, bo.getStorageId());
        lqw.eq(StringUtils.isNotBlank((bo.getIsStaging())), DrugImportMaster::getIsStaging, bo.getIsStaging());
        lqw.eq(bo.getImportDate() != null, DrugImportMaster::getImportDate, bo.getImportDate());
        lqw.eq(StringUtils.isNotBlank(bo.getSupplier()), DrugImportMaster::getSupplier, bo.getSupplier());
        lqw.eq(StringUtils.isNotBlank(bo.getStorageFrom()), DrugImportMaster::getStorageFrom, bo.getStorageFrom());
        lqw.eq(bo.getAccountReceivable() != null, DrugImportMaster::getAccountReceivable, bo.getAccountReceivable());
        lqw.eq(bo.getAccountPayed() != null, DrugImportMaster::getAccountPayed, bo.getAccountPayed());
        lqw.eq(bo.getAdditionalFee() != null, DrugImportMaster::getAdditionalFee, bo.getAdditionalFee());
        lqw.eq(StringUtils.isNotBlank(bo.getImportClass()), DrugImportMaster::getImportClass, bo.getImportClass());
        lqw.eq(StringUtils.isNotBlank(bo.getAccountType()), DrugImportMaster::getAccountType, bo.getAccountType());
        lqw.eq(StringUtils.isNotBlank(bo.getAccountIndicator()), DrugImportMaster::getAccountIndicator, bo.getAccountIndicator());
        lqw.eq(bo.getAcctDate() != null, DrugImportMaster::getAcctDate, bo.getAcctDate());
        lqw.eq(StringUtils.isNotBlank(bo.getAcctOperator()), DrugImportMaster::getAcctOperator, bo.getAcctOperator());
        lqw.eq(StringUtils.isNotBlank(bo.getTally()), DrugImportMaster::getTally, bo.getTally());
        lqw.eq(bo.getTallyDate() != null, DrugImportMaster::getTallyDate, bo.getTallyDate());
        lqw.eq(StringUtils.isNotBlank(bo.getTallyOperator()), DrugImportMaster::getTallyOperator, bo.getTallyOperator());
        lqw.eq(StringUtils.isNotBlank(bo.getOrgId()), DrugImportMaster::getOrgId, bo.getOrgId());
        lqw.eq(StringUtils.isNotBlank(bo.getVoucherNo()), DrugImportMaster::getVoucherNo, bo.getVoucherNo());
        lqw.eq(StringUtils.isNotBlank(bo.getRecoveryDocNo()), DrugImportMaster::getRecoveryDocNo, bo.getRecoveryDocNo());
        lqw.eq(StringUtils.isNotBlank(bo.getRemarks()), DrugImportMaster::getRemarks, bo.getRemarks());
        lqw.eq(StringUtils.isNotBlank(bo.getIsStaging()), DrugImportMaster::getIsStaging, bo.getIsStaging());
        lqw.between(params.get("beginTime") != null && params.get("endTime") != null,
                DrugImportMaster::getCreateTime, DateUtils.dateTime(params.get("beginTime")), DateUtils.dateTime(params.get("endTime")));
        lqw.orderByAsc(DrugImportMaster::getImportDate);
        return lqw;
    }

    /**
     * 新增药品入库主表
     */
    @Override
    @GlobalTransactional
    public DrugImportMaster insertByBo(DrugImportMasterBo bo) {
        boolean flag = false;
        DrugImportMaster add = BeanUtil.toBean(bo, DrugImportMaster.class);
        String documentNo = "000000";
        // Todo 生成药品入库流水号
        if (StringUtils.equals(bo.getIsStaging(), UserConstants.NO)) {
            add.setImportDate(new Date());
            documentNo = remoteSerialNumberUtils.generateDrugImportNo(LoginHelper.getLoginUser().getOrgId(), "rkd");
        }
        // 判断前台传入的数据是不是已经暂存的数据(或者直接保存入库)
        if (StringUtils.isBlank(bo.getId()) && StringUtils.equals(bo.getIsStaging(), UserConstants.YES) ||
                StringUtils.isBlank(bo.getId()) && StringUtils.equals(bo.getIsStaging(), UserConstants.NO)) {
            // 暂存
            add.setDocumentNo(documentNo);
            bo.setDocumentNo(documentNo);
            validEntityBeforeSave(add);
            add.initEntity();
            flag = baseMapper.insert(add) > 0;
            if (flag) {
                bo.setId(add.getId());
            }
        } else if (StringUtils.isNotBlank(bo.getId()) &&
                (StringUtils.equals(bo.getIsStaging(), UserConstants.NO)
                        || StringUtils.equals(bo.getIsStaging(), UserConstants.YES))) {
            add.setDocumentNo(documentNo);
            flag = baseMapper.updateById(add) > 0;
        }
        // TODO 保存、修改入库记录明细表
        initImportDetail(bo);
        // 明细保存
        drugImportDetailService.batchDrugImportInfo(bo);
//        //TODO 是否采购入库、建账入库 （如果是入库的同时会自动生成库存数据）
//        if (StringUtils.equals(BaseConstants.IS_PURCHASE, bo.getImportClass())
//                || StringUtils.equals(BaseConstants.IS_SET_ACCOUNT_BOOK, bo.getImportClass())) {
        // 库存量保存
        if (StringUtils.equals(bo.getIsStaging(), UserConstants.NO)) {
            bo.setRecordType(DrugConstants.FIVE);
            List<DrugStock> drugStocks = drugStockService.batchDrugStockInfo(bo);
        }
//        }
        return add;
    }

    /**
     * 组织保存入库明细数据
     *
     * @param bo
     */
    public void initImportDetail(DrugImportMasterBo bo) {
        List<DrugStockBo> drugStockBoList = new ArrayList<>();
        if (ObjectUtil.isNotNull(bo) && CollectionUtil.isNotEmpty(bo.getDetailListSave())) {
            bo.getDetailListSave().forEach(item -> {
                // 查询对应药品的药品info信息
                DrugInfoVo drugInfoVo = drugInfoVoMap.get(item.getDrugInfoId());
                if (ObjectUtil.isNull(drugInfoVo)) {
                    String errorMsg = "第" + item.getItemNo() + "行，药品：" + item.getItemInfo() + "基本信息为空，请编辑后重新选择入库";
                    log.error("logErrorLog" + "入库单号为：" + bo.getDocumentNo() + errorMsg);
                    throw new RuntimeException(errorMsg);
                }
                // 查询对应药品的药品价表信息
                DrugPriceBo drugPriceBo = new DrugPriceBo();
                drugPriceBo.setDrugInfoId(item.getDrugInfoId());
                List<DrugPriceVo> drugPriceVos = drugPriceService.queryList(drugPriceBo);
                if (CollectionUtil.isEmpty(drugPriceVos)) {
                    String errorMsg = "第" + item.getItemNo() + "行，药品：" + drugInfoVo.getDrugName() + "价表信息为空，请编辑后重新选择入库";
                    log.error("logErrorLog" + "入库单号为：" + bo.getDocumentNo() + errorMsg);
                    throw new RuntimeException(errorMsg);
                }
                DrugPriceVo drugPriceVo = drugPriceVos
                        .stream().filter(priceVo -> StringUtils.equals(priceVo.getPriceId(), item.getDrugPriceId())).collect(Collectors.toList()).get(0);
//                DrugPriceVo minPriceVo = drugPriceVos
//                        .stream().filter(priceVo -> StringUtils.equals(priceVo.getPackSize(), BaseConstants.IS_SMALL_PACK)).collect(Collectors.toList()).get(0);
//                DrugPriceVo maxPriceVo = drugPriceVos
//                        .stream().filter(priceVo -> StringUtils.equals(priceVo.getPackSize(), "2")).collect(Collectors.toList()).get(0);
                item.setPackSize(drugPriceVo.getPackSize());
                item.setMinSpec(drugInfoVo.getMinSpec());
                item.setMinUnits(drugInfoVo.getMinUnits());
                item.setAllStock(item.getQuantity());
                item.setMasterId(bo.getId());
                item.setCreateBy("");
                item.setCreateBy(null);
                item.setUpdateBy("");
                item.setUpdateTime(null);
                item.setSupplier(StringUtils.isNotBlank(item.getSupplier()) ?
                        item.getSupplier() : drugInfoVo.getSupplierId());
                if (StringUtils.isBlank(item.getId())) {
                    item.setId(SnowIdUtils.uniqueString());
                }
                // 组织保存库存明细数据 initDrugStock()
                item.setDrugInfoVo(drugInfoVo);
                drugStockBoList.add(initDrugStock(bo, item));
            });
            bo.setStockBoList(drugStockBoList);
        }
    }


    /**
     * 组织保存库存明细数据
     *
     * @param bo
     * @param item
     * @return
     */
    public DrugStockBo initDrugStock(DrugImportMasterBo bo, DrugImportDetailBo item) {
        //TODO 是否采购入库、建账入库 （如果是入库的同时会自动生成库存数据）
        DrugStockBo drugStockBo = BeanUtil.toBean(item, DrugStockBo.class);
//        if (StringUtils.equals(BaseConstants.IS_PURCHASE, bo.getImportClass())
//                || StringUtils.equals(BaseConstants.IS_SET_ACCOUNT_BOOK, bo.getImportClass())) {
        drugStockBo.setDrugInfoId(item.getDrugInfoId());
        drugStockBo.setDrugPriceId(item.getDrugPriceId());
        DrugStorageDeptVo storageDeptVo = drugStorageDeptService.queryById(bo.getStorageId());
        if (ObjectUtil.isNull(storageDeptVo)) {
            String errorMsg = "入库科室不存在，请重新选择。";
            log.error("logErrorLog" + "入库单号为：" + bo.getDocumentNo() + errorMsg);
            throw new RuntimeException(errorMsg);
        }
        drugStockBo.setStorageName(storageDeptVo.getStorageName());

//        Integer packageNum = (BigDecimal.valueOf(item.getPackageNum()));
        drugStockBo.setPackageNum(item.getPackageNum());
        drugStockBo.setRetailPriceMin(item.getRetailPriceMin());
        drugStockBo.setTradePriceMin(item.getRetailPriceMin());
        drugStockBo.setRetailPrice(item.getRetailPrice());
        drugStockBo.setTradePrice(item.getRetailPrice());
        drugStockBo.setMinSpec(item.getMinSpec());
//        // 药品规格、价钱相同，但批次不同的药品保存id相同
//        String identicalInfoId = getSamePriceStock(bo, item);
//        drugStockBo.setIdenticalInfoId(identicalInfoId);
        // 判断是不是小包装 true 小包装
        if (StringUtils.equals(item.getPackSize(), BaseConstants.IS_SMALL_PACK)) {
//            // 小包装进货价
//            drugStockBo.setTradePriceMin(item.getTradePrice());
//            // 小包装零售价
//            drugStockBo.setRetailPriceMin(item.getRetailPrice());
//            drugStockBo.setTradePrice(item.getTradePrice().multiply(packageNum));
//            drugStockBo.setRetailPrice(item.getRetailPrice().multiply(packageNum));
        } else {
//            // 大包装进货价(四位小数)
//            drugStockBo.setTradePriceMin(item.getTradePrice().divide(packageNum, RoundingMode.HALF_UP));
//            // 大包装零售价
//            drugStockBo.setRetailPriceMin(item.getRetailPrice().divide(packageNum, RoundingMode.HALF_UP));
            drugStockBo.setQuantity(item.getQuantity() * item.getPackageNum());
        }
        drugStockBo.setNetworkPrice(drugStockBo.getRetailPrice());
        drugStockBo.setIsSupply(UserConstants.YES);
        drugStockBo.setNetworkPriceMin(drugStockBo.getRetailPriceMin());
        // 入库单号
        drugStockBo.setDocumentNo(bo.getDocumentNo());
        // 设置入库主记录id
        drugStockBo.setImportMasterId(bo.getId());
        drugStockBo.setSupplierId(item.getSupplier());
        drugStockBo.setStorageId(bo.getStorageId());
        drugStockBo.setInventoryIsShow(UserConstants.YES);
        drugStockBo.setDrugInfoVo(item.getDrugInfoVo());
        drugStockBo.setDrugImportDetailBo(item);
        // 设置库存流转类型为 入库 “5”
        drugStockBo.setRecordType(DrugConstants.FIVE);
        // 写入库存表
//        }
        return drugStockBo;
    }

    /**
     * 修改药品入库主表
     */
    @Override
    public Boolean updateByBo(DrugImportMasterBo bo) {
        DrugImportMaster update = BeanUtil.toBean(bo, DrugImportMaster.class);
        update.updateInfo();
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(DrugImportMaster entity) {
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除药品入库主表
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<String> ids, Boolean isValid) {
        if (isValid) {
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }

    /**
     * @return
     * @Author zhangpeng
     * @Description // 入库药品检索
     * @ date 17:54 2023/6/23
     * @Param * @param null
     **/
    @Override
    public List<DrugImportMasterVo> getAutoDrugPriceInfo(DrugImportMasterBo bo) {
        return baseMapper.getAutoDrugPriceInfo(bo);
    }

    /**
     * 确认入库
     *
     * @param exportId
     * @return
     */
    @Override
    @GlobalTransactional
    public boolean confirmImport(String exportId) {
        int deductionQuantity = 0;
        List<DrugStock> updateQuantityList = new ArrayList<>();
        DrugExportMasterVo drugExportMasterVo = exportMasterMapper.selectVoById(exportId);
        // 检验出库信息
        verifyExportMaster(drugExportMasterVo);
        List<DrugExportDetail> drugExportDetailList = drugExportDetailMapper.selectList(Wrappers.<DrugExportDetail>lambdaQuery()
                .eq(DrugExportDetail::getMasterId, exportId)
        );
        List<String> stockIds = drugExportDetailList.stream().map(DrugExportDetail::getStockId).collect(Collectors.toList());
        List<DrugStock> drugStocks = drugStockMapper.selectList(Wrappers.<DrugStock>lambdaQuery()
                .in(DrugStock::getId, stockIds)
        );

        Map<String, Integer> detailMap = drugExportDetailList.stream()
                .collect(Collectors.groupingBy(DrugExportDetail::getStockId, Collectors.summingInt(po -> {
                    // 出库数量 装换小包装
                    return StringUtils.equals(po.getPackSize(), BaseConstants.IS_SMALL_PACK) ?
                            po.getQuantity() : po.getQuantity() * po.getPackageNum();
                })));

//        Map<String, List<DrugExportDetail>> detailMap = drugExportDetailList.stream()
//                .collect(Collectors.groupingBy(DrugExportDetail::getStockId));
        detailMap.forEach((stockId, value) -> {
            List<DrugStock> drugStockList = drugStocks.stream()
                    .filter(stock -> StringUtils.equals(stock.getId(), stockId)).collect(Collectors.toList());
            if (CollectionUtil.isNotEmpty(drugStockList)) {
                DrugStock drugStock = new DrugStock();
                DrugStock selectDrugStock = drugStockList.get(0);
                if (value > selectDrugStock.getQuantity()) {
                    throw new RuntimeException("库存已不足，不能进行确认操作，请联系上级库房重新出库。");
                }
                drugStock.setQuantity(selectDrugStock.getQuantity() - value);
                drugStock.setId(selectDrugStock.getId());
                updateQuantityList.add(drugStock);
                //修改扣减库存
                drugStockMapper.updateById(drugStock);
            }
        });
        DrugStockAllLogParamVo drugStockAllLogParamVo = new DrugStockAllLogParamVo();
        drugStockAllLogParamVo.setRecordType(DrugConstants.SIX);
        drugExportMasterVo.setDetailListSave(BeanUtil.copyToList(drugExportDetailList, DrugExportDetailBo.class));
        drugStockAllLogParamVo.setDrugExportMasterBo(BeanUtil.toBean(drugExportMasterVo, DrugExportMasterBo.class));
        tissueImportInfo(drugExportMasterVo, drugExportDetailList);
        // 保存库存流转明细
        stockAllLogService.caseRecordTypeSave(drugStockAllLogParamVo);
        return Boolean.TRUE;
    }

    @Transactional
    public void tissueImportInfo(DrugExportMasterVo drugExportMasterVo, List<DrugExportDetail> drugExportDetailList) {
        List<DrugImportDetailBo> detailListSave = new ArrayList<>();
        DrugImportMasterBo drugImportMasterBo = new DrugImportMasterBo();
//        drugImportMasterBo.setId(SnowIdUtils.uniqueString());
        drugImportMasterBo.setImportClass("0");
        drugImportMasterBo.setIsStaging(UserConstants.NO);
        drugImportMasterBo.setAccountType("1");
        // 供货单位
        drugImportMasterBo.setStorageFrom(drugExportMasterVo.getStorageId());
        // 接收单位
        drugImportMasterBo.setStorageId(drugExportMasterVo.getReceiverId());
        drugImportMasterBo.setOrgId(drugExportMasterVo.getOrgId());
        drugImportMasterBo.setAccountPayed(drugExportMasterVo.getAccountPayed());
        drugImportMasterBo.setAccountReceivable(drugExportMasterVo.getAccountReceivable());
        drugExportDetailList.forEach(detail -> {
            DrugImportDetailBo drugImportDetailBo = BeanUtil.toBean(detail, DrugImportDetailBo.class);
            drugImportDetailBo.setCreateBy("");
            drugImportDetailBo.setCreateBy(null);
            drugImportDetailBo.setUpdateBy("");
            drugImportDetailBo.setUpdateTime(null);
            drugImportDetailBo.setSupplier(detail.getSupplierId());
            drugImportDetailBo.setExpireDate(detail.getExpireDate());
            drugImportDetailBo.setProduceDate(detail.getProduceDate());
            drugImportDetailBo.setTradePrice(detail.getPurchasePrice());
            if (StringUtils.equals(detail.getPackSize(), BaseConstants.IS_SMALL_PACK)) {
                // 小包装
                drugImportDetailBo.setCurrentSpec(detail.getMinSpec());
                drugImportDetailBo.setQuantity(detail.getQuantity());
            }
            detailListSave.add(drugImportDetailBo);
            drugImportMasterBo.setDetailListSave(detailListSave);
        });
        DrugImportMaster drugImportMaster = insertByBo(drugImportMasterBo);
        drugExportMasterMapper.update(null, Wrappers.<DrugExportMaster>lambdaUpdate()
                .set(DrugExportMaster::getImportMasterId, drugImportMaster.getId())
                .set(DrugExportMaster::getImportOperator, drugImportMaster.getCreateBy())
                .set(DrugExportMaster::getImportDate, drugImportMaster.getImportDate())
                .set(DrugExportMaster::getReceiverUserId, drugImportMaster.getCreateBy())
                .eq(DrugExportMaster::getExportId, drugExportMasterVo.getExportId())
        );
    }

    /**
     * 检验出库信息
     *
     * @param drugExportMasterVo
     */
    public void verifyExportMaster(DrugExportMasterVo drugExportMasterVo) {
        if (ObjectUtil.isNull(drugExportMasterVo)) {
            throw new RuntimeException("申请单已删除，不能进行确认操作，请点击【刷新】按钮。");
        }
        if (StringUtils.isNotBlank(drugExportMasterVo.getImportMasterId())) {
            throw new RuntimeException("申请单已确认，不能进行确认操作，请点击【刷新】按钮。");
        }
    }

}
